import { Directive, ElementRef, Input, OnChanges } from '@angular/core';


@Directive({
  selector:'[images]'
})

export class ImagesDirective implements OnChanges{
  @Input('images') url:string;
  @Input('show') show:boolean;
  constructor(
    private elementRef:ElementRef,
  ){
    this.show=false;
  }


  ngOnChanges(){
    let images = new Image();

    images.onload = () => {
      this.elementRef.nativeElement.src = this.url;
    };

    images.onerror = () => {
      this.elementRef.nativeElement.src = './assets/images/default.jpg';
    };
    if(this.url!=undefined){
      images.src = this.url;
    }
  }




}
